/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package l1j.server.server;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.logging.Logger;

import l1j.server.Config;

public class GeneralThreadPool {
	private static Logger _log = Logger.getLogger(GeneralThreadPool.class
			.getName());

	private static GeneralThreadPool _instance;

	private Executor _executor;
	
	public static GeneralThreadPool getInstance() {
		if (_instance == null){
			_instance = new GeneralThreadPool();
		}
		return _instance;
	}
	
	private GeneralThreadPool() {
		if ( Config.THREAD_P_TYPE_GENERAL == 1 ) {
			_executor = Executors
					.newFixedThreadPool(Config.THREAD_P_SIZE_GENERAL);
		} else if (Config.THREAD_P_TYPE_GENERAL == 2) {
			_executor = Executors.newCachedThreadPool();
		} else {
			_executor = null;
		}
	}
	
	public void execute(Runnable r) {
		if ( _executor == null ) {
			Thread t = new Thread(r);
			t.start();
		} else {
			_executor.execute(r);
		}
	}
	
	public void execute(Thread t) {
		t.start();
	}
}
